﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
namespace Web.manager
{
    public partial class PhoneBookManager : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SetDivePage(ref GridView1, ref GV);
            if (!IsPostBack)
            {
                QueryData();
            }
        }

        public override void QueryData()
        {
            DataSet ds = PhoneBook.Group.Group.query_isopen(this.txb_keyword.Text);
            //绑定数据集
            GVDataBind(ref GridView1, ref GV, ds);
        }

        public void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "del":
                    string groupid = e.CommandArgument.ToString();
                    Hashtable group = PhoneBook.Group.Group.get(Commons.StrUtil.FormatValue(groupid));
                    group["isdel"] = "1";
                    group["groupid"] = groupid;
                    ERMap.ERMapHelper.setmodel("b_group", "groupid", group);
                    AddLog("删除了集团通讯信息：{0}({1})", group["groupname"], group["groupid"]);
                    Helper.ShowMessage(u_message, controls.UCMessageType.success, "删除成功");
                    QueryData();
                    break;
                case "update":
                    string groupidt = e.CommandArgument.ToString();
                    Response.Redirect("groupedit.aspx?groupid=" + groupidt);
                    break;
                case "enabled":
                    string groupid1 = e.CommandArgument.ToString();
                    Hashtable group1 = PhoneBook.Group.Group.get(Commons.StrUtil.FormatValue(groupid1));
                    if (group1["enabled"].ToString() == "1")
                        group1["enabled"] = "0";
                    else
                        group1["enabled"] = "1";
                    group1["groupid"] = groupid1;
                    ERMap.ERMapHelper.setmodel("b_group", "groupid", group1);
                    QueryData();
                    break;
                default:
                    break;
            }
        }

        protected void btn_query_Click(object sender, EventArgs e)
        {
            QueryData();
        }

        protected void btn_export_Click(object sender, EventArgs e)
        {
            string filename = string.Format("groups{0}", Commons.StringUtil.GetID_15());
            Commons.FileUtil.GridExportExcel(GridView1, filename);
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow )
            {
                string groupid=this.GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
                ((ImageButton)e.Row.FindControl("btn_update")).CommandArgument = groupid;
                ((ImageButton)e.Row.FindControl("btn_del")).CommandArgument = groupid;
                //string enabled = DataBinder.Eval(e.Row.DataItem, "enabled").ToString();
                //if(enabled=="1")e.Row.Cells[5].Text="暂停";
                //else e.Row.Cells[5].Text="正常";
            }
        }
    }
}